package com.ruoyi.animal.service.impl;

import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.animal.mapper.AnimalCareMapper;
import com.ruoyi.animal.domain.AnimalCare;
import com.ruoyi.animal.service.IAnimalCareService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 动物照料Service业务层处理
 * 
 * @author gw
 * @date 2025-01-06
 */
@Service
public class AnimalCareServiceImpl implements IAnimalCareService 
{
    @Autowired
    private AnimalCareMapper animalCareMapper;

    /**
     * 查询动物照料
     * 
     * @param careId 动物照料主键
     * @return 动物照料
     */
    @Override
    public AnimalCare selectAnimalCareByCareId(Long careId)
    {
        return animalCareMapper.selectAnimalCareByCareId(careId);
    }

    /**
     * 查询动物照料列表
     * 
     * @param animalCare 动物照料
     * @return 动物照料
     */
    @Override
    public List<AnimalCare> selectAnimalCareList(AnimalCare animalCare)
    {
        return animalCareMapper.selectAnimalCareList(animalCare);
    }

    /**
     * 新增动物照料
     * 
     * @param animalCare 动物照料
     * @return 结果
     */
    @Override
    @Transactional
    public int insertAnimalCare(AnimalCare animalCare)
    {
        animalCare.setCreateTime(DateUtils.getNowDate());
        animalCare.setCreateBy(SecurityUtils.getUsername());
        return animalCareMapper.insertAnimalCare(animalCare);
    }

    /**
     * 修改动物照料
     * 
     * @param animalCare 动物照料
     * @return 结果
     */
    @Override
    public int updateAnimalCare(AnimalCare animalCare)
    {
        animalCare.setUpdateTime(DateUtils.getNowDate());
        animalCare.setUpdateBy(SecurityUtils.getUsername());
        return animalCareMapper.updateAnimalCare(animalCare);
    }

    /**
     * 批量删除动物照料
     * 
     * @param careIds 需要删除的动物照料主键
     * @return 结果
     */
    @Override
    @Transactional
    public int deleteAnimalCareByCareIds(Long[] careIds)
    {
        int deletedCount = 0;
        for (Long careId : careIds) {
            AnimalCare animalCare = animalCareMapper.selectAnimalCareByCareId(careId);
            if (animalCare != null) {
                animalCare.setDeleteBy(SecurityUtils.getUsername());
                animalCare.setDeleteTime(DateUtils.getNowDate());
                animalCare.setDelFlag(1);
                animalCareMapper.updateAnimalCare(animalCare);
                deletedCount++;
            }
        }
        return deletedCount;
    }

    /**
     * 删除动物照料信息
     * 
     * @param careId 动物照料主键
     * @return 结果
     */
    @Override
    public int deleteAnimalCareByCareId(Long careId)
    {
        AnimalCare animalCare = animalCareMapper.selectAnimalCareByCareId(careId);
        animalCare.setDeleteBy(SecurityUtils.getUsername());
        animalCare.setDeleteTime(DateUtils.getNowDate());
        animalCare.setDelFlag(1);
        return animalCareMapper.updateAnimalCare(animalCare);
    }
}
